package com.atguigu.yygh.common.result;

import lombok.Getter;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

@ToString
@Getter
public class R {
    private Boolean success;
    private Integer code;
    private String message;
    private Map<String,Object> data = new HashMap<String, Object>();

    private R(){}

    public static R ok(){
        R r = new R();
        r.code= REnum.SUCCESS.getCode();
        r.success= REnum.SUCCESS.getFlag();
        r.message= REnum.SUCCESS.getMessage();
        return r;
    }

    public static R error(){
        R r = new R();
        r.code= REnum.ERROR.getCode();
        r.success= REnum.ERROR.getFlag();
        r.message= REnum.ERROR.getMessage();
        return r;
    }

//    设置修改code的值
    public R Code(Integer Code){
        this.code = Code;
        return this;
    }

    public R Success(Boolean success){
        this.success=success;
        return this;
    }

    public R Message(String message){
        this.message=message;
        return this;
    }

    public R data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public R data(Map<String,Object> map){
        this.data=map;
        return this;
    }
}
